<?php include('header.php');?>
<?php
$rDel = explode("#", $_POST['rID']);
mysql_query("DELETE FROM reservation_session WHERE reservation_detail_id = '$rDel[0]' AND reservation_checkin = '$rDel[1]'");

$sQuery = mysql_query("SELECT max(reservation_session_id) as reservation_session_id FROM reservation_session");
$sRow = mysql_fetch_array($sQuery);
$sNum = $sRow['reservation_session_id'];

//จัดการตาราง reservation_session
if($_POST['action']=='add'){
	$dQuery = mysql_query("SELECT reservation_checkin FROM reservation WHERE reservation_checkin = '$rDel[1]'");
	while($dRow = mysql_fetch_array($dQuery)){
		$rSQuery = mysql_query("SELECT room_id,reservation_checkin,reservation_detail_id,reservation_status FROM reservation WHERE reservation_checkin='".$dRow['reservation_checkin']."' ");
		while($rSRow = mysql_fetch_array($rSQuery)){
			$sNum++;
			mysql_query("INSERT INTO reservation_session (reservation_session_id,room_id,reservation_checkin,reservation_detail_id,reservation_status) VALUES ('$sNum','".$rSRow['room_id']."','".$rSRow['reservation_checkin']."','".$rSRow['reservation_detail_id']."','".$rSRow['reservation_status']."')");
		}
	}
}
//จบ จัดการตาราง reservation_session

for($i=0; $i<count($_POST['rCheck']); $i++){
	$sNum++;
	$room = explode("#", $_POST['rCheck'][$i]);
	//$room_ses_id = $i+1;
	//echo $room[0]." ".$room[1]." ".$room[2]."<br>";
	mysql_query("INSERT INTO reservation_session (reservation_session_id,room_id,reservation_checkin,reservation_detail_id,reservation_status) VALUES ('$sNum','$room[0]','$rDel[1]','$rDel[0]','$room[1]')");
}

echo "<script>window.location='room_edit_detail.php?id=".$rDel[0]."';</script>";
?>
<?php include('footer.php');?>
